package main

import (
	"fmt"
	"gorm.io/gorm"
	"time"
)
import "gorm.io/driver/mysql"

func main() {
	fmt.Println(time.Now())
	t := new(time.Time)
	print(t)

	db, err3 := gorm.Open(mysql.Open("root:123456@tcp(192.168.1.4:3306)/go_admin?charset=utf8mb4&parseTime=True&loc=Local"))
	if err3 != nil {
		fmt.Println(err3)
	} else {
		//ui := User2{Id: 112, Name: "2222"}
		ui := TbDemo{Name: "abc", Age: "12", CreatedAt: time.Now(), UpdatedAt: time.Now()}
		ui.ControlBy = ControlBy{CreateBy: 1, UpdateBy: 2}
		db.Create(ui) //创建数据
	}

}

type User2 struct {
	Id   int64
	Name string
}

type Model struct {
	Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
}

type ControlBy struct {
	CreateBy int `json:"createBy" gorm:"index;comment:创建者"`
	UpdateBy int `json:"updateBy" gorm:"index;comment:更新者"`
}
type TbDemo struct {
	//Model
	Name      string         `json:"name" gorm:"type:varchar(128);comment:名  称"`
	Age       string         `json:"age" gorm:"type:int;comment:年龄"`
	CreatedAt time.Time      `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt time.Time      `json:"updatedAt" gorm:"comment:最后更新时间"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:删除时间"`
	ControlBy
}

func (TbDemo) TableName() string {
	return "tb_demo"
}
